﻿using FileManagerSystem.DbInfos;
using LiteDB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace FileManagerSystem.Service
{
    public interface IBaseService<TEntity> where TEntity : class, new()
    {
        #region 查询
        /// <summary>
        /// 查询全部 --不分页
        /// </summary>
        /// <returns></returns>
        public Task<List<TEntity>> FindAll(Expression<Func<TEntity, bool>> expression);

        /// <summary>
        /// 查询指定多条 --分页
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public Task<TEntityPaged<TEntity>> FindAllToPage(Expression<Func<TEntity, bool>> expression, int page, int size);

        /// <summary>
        /// 查询指定一条
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public Task<TEntity> FindOne(Expression<Func<TEntity, bool>> expression);

        /// <summary>
        /// 检查对象是否存在
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public Task<bool> FindExist(Expression<Func<TEntity, bool>> expression);
        #endregion

        #region 新增
        /// <summary>
        /// 单条新增
        /// </summary>
        /// <param name="forecast"></param>
        /// <returns></returns>
        public Task<BsonValue> Insert(TEntity forecast);

        /// <summary>
        /// 单条新增 通过Guid新增
        /// </summary>
        /// <param name="forecast"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public Task<BsonValue> Insert(TEntity forecast, BsonAutoId type);

        /// <summary>
        /// 多条新增
        /// </summary>
        /// <param name="forecast"></param>
        /// <returns></returns>
        public Task<int> BulkInsert(List<TEntity> forecast);
        #endregion

        #region 更新
        /// <summary>
        /// 单条更新
        /// </summary>
        /// <param name="forecast"></param>
        /// <returns></returns>
        public Task<bool> Update(TEntity forecast);
        #endregion

        #region 删除
        /// <summary>
        /// 单挑删除
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        public Task<bool> Delete(BsonValue id);

        /// <summary>
        /// 多条删除
        /// </summary>
        /// <param name="expression">删除条件</param>
        /// <returns></returns>
        public Task<int> DeleteMany(Expression<Func<TEntity, bool>> expression);
        #endregion
    }
}
